package com.ruoyi.hospital.medication.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.medication.domain.TMedication;
import com.ruoyi.hospital.medication.service.ITMedicationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品管理Controller
 * 
 * @author Shawn
 * @date 2024-02-21
 */
@Controller
@RequestMapping("/hospital/medication")
public class TMedicationController extends BaseController
{
    private String prefix = "hospital/medication";

    @Autowired
    private ITMedicationService tMedicationService;

    @RequiresPermissions("hospital:medication:view")
    @GetMapping()
    public String medication()
    {
        return prefix + "/medication";
    }

    /**
     * 查询药品管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TMedication tMedication)
    {
        startPage();
        List<TMedication> list = tMedicationService.selectTMedicationList(tMedication);
        return getDataTable(list);
    }

    /**
     * 导出药品管理列表
     */
    @RequiresPermissions("hospital:medication:export")
    @Log(title = "药品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TMedication tMedication)
    {
        List<TMedication> list = tMedicationService.selectTMedicationList(tMedication);
        ExcelUtil<TMedication> util = new ExcelUtil<TMedication>(TMedication.class);
        return util.exportExcel(list, "药品管理数据");
    }

    /**
     * 新增药品管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存药品管理
     */
    @RequiresPermissions("hospital:medication:add")
    @Log(title = "药品管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TMedication tMedication)
    {
        return toAjax(tMedicationService.insertTMedication(tMedication));
    }

    /**
     * 修改药品管理
     */
    @RequiresPermissions("hospital:medication:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TMedication tMedication = tMedicationService.selectTMedicationById(id);
        mmap.put("tMedication", tMedication);
        return prefix + "/edit";
    }

    /**
     * 修改保存药品管理
     */
    @RequiresPermissions("hospital:medication:edit")
    @Log(title = "药品管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TMedication tMedication)
    {
        return toAjax(tMedicationService.updateTMedication(tMedication));
    }

    /**
     * 删除药品管理
     */
    @RequiresPermissions("hospital:medication:remove")
    @Log(title = "药品管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tMedicationService.deleteTMedicationByIds(ids));
    }


    @RequestMapping("/selectMedication")
    public String selectDoctor() {
        return prefix + "/selectMedication";
    }


}
